package com.gemantic.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author Mr.Null
 * @date 2018年2月1日 下午7:56:12
 */
@RestController
public class CustomerController {
	
	Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	LoadBalancerClient loadBalancerClient;
	@Autowired
	RestTemplate restTemplate;
	
	@GetMapping("/customer")
	public String doGet() {
		ServiceInstance instance = loadBalancerClient.choose("provider-service");
		String url = "http://" + instance.getHost() + ":" + instance.getPort() + "/doGet";
        logger.info(url);
        return restTemplate.getForObject(url, String.class);
	}
	
}
